﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace System
{
    public interface ITM
    {
        /// <summary>
        /// 添加对象到库中
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="model">待处理对象</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <returns>添加失败则返回0,成功则返回1</returns>
        int _Add<Tm>(Tm model, string fields) where Tm : BaseModel, new();

        /// <summary>
        /// 添加集合到库中
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="list">待处理对象集合</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <returns>添加失败则返回0,成功则返回集合数目</returns>
        int _Add<Tm>(List<Tm> list, string fields) where Tm : BaseModel, new();

        /// <summary>
        /// 添加对象到库中
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="model">待处理对象</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="tableName">待处理对象在数据库中对应表名</param>
        /// <returns>添加失败则返回0,成功则返回1</returns>
        int _Add<Tm>(Tm model, string fields, string tableName) where Tm : BaseModel, new();

        /// <summary>
        /// 添加对象集合到库中
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="list">待处理对象集合</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="tableName">待处理对象在数据库中对应表名</param>
        /// <returns>添加失败则返回0,成功则返回集合数目</returns>
        int _Add<Tm>(List<Tm> list, string fields, string tableName) where Tm : BaseModel, new();

        /// <summary>
        /// 从数据库中删除对象
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="model">待处理对象</param>
        /// <returns>删除失败返回0，成功则返回1</returns>
        int _Remove<Tm>(Tm model) where Tm : BaseModel, new();

        /// <summary>
        /// 从数据库中删除对象集合
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="list">待处理对象集合</param>
        /// <returns>删除失败返回0，成功则返回集合数目</returns>
        int _Remove<Tm>(List<Tm> list) where Tm : BaseModel, new();

        /// <summary>
        /// 删除对应ID的对象
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="id">对象ID</param>
        /// <returns>删除失败返回0，成功则返回1</returns>
        int _Remove<Tm>(string id) where Tm : BaseModel, new();

        /// <summary>
        /// 从数据库中特定表中删除对象
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="model">待处理对象</param>
        /// <param name="tableName">待处理对象在数据库中对应表名</param>
        /// <returns>删除失败返回0，成功则返回1</returns>
        int _Remove<Tm>(Tm model, string tableName) where Tm : BaseModel, new();

        /// <summary>
        /// 从数据库中特定表中删除对象集合
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="list">待处理对象集合</param>
        /// <param name="tableName">待处理对象在数据库中对应表名</param>
        /// <returns>删除失败返回0，成功则返回集合数目</returns>
        int _Remove<Tm>(List<Tm> list, string tableName) where Tm : BaseModel, new();

        /// <summary>
        /// 从数据库中特定表中删除对象ID的对象
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="id">对象ID</param>
        /// <param name="tableName">待处理对象在数据库中对应表名</param>
        /// <returns>删除失败返回0，成功则返回1</returns>
        int _Remove<Tm>(string id, string tableName) where Tm : BaseModel, new();

        /// <summary>
        /// 修改对象
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="model">待处理对象</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <returns>修改失败返回0，成功则返回1</returns>
        int _Modify<Tm>(Tm model, string fields) where Tm : BaseModel, new();

        /// <summary>
        /// 修改对象集合
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="list">待处理对象集合</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <returns>返回受影响的记录数</returns>
        int _Modify<Tm>(List<Tm> list, string fields) where Tm : BaseModel, new();

        /// <summary>
        /// 修改对象
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="model">待处理对象</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="tableName">待处理对象在数据库中对应表名</param>
        /// <returns>返回受影响的记录数</returns>
        int _Modify<Tm>(Tm model, string fields, string tableName) where Tm : BaseModel, new();

        /// <summary>
        /// 修改集合中对象
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="list">待处理对象集合</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="tableName">待处理对象在数据库中对应表名</param>
        /// <returns>返回受影响的记录数</returns>
        int _Modify<Tm>(List<Tm> list, string fields, string tableName) where Tm : BaseModel, new();

        /// <summary>
        /// 新增或修改对象，如对象存在则修改对象，反之则新增对象
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="model">待处理对象</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <returns>返回受影响的记录数</returns>
        int _AddOrModify<Tm>(Tm model, string fields) where Tm : BaseModel, new();

        /// <summary>
        ///  新增或修改集合中对象，如对象存在则修改对象，反之则新增对象
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="list">待处理对象集合</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <returns>返回受影响的记录数</returns>
        int _AddOrModify<Tm>(List<Tm> list, string fields) where Tm : BaseModel, new();

        /// <summary>
        ///  新增或修改对象，如对象存在则修改对象，反之则新增对象
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="model">待处理对象</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="tableName">待处理对象在数据库中对应表名</param>
        /// <returns>返回受影响的记录数</returns>
        int _AddOrModify<Tm>(Tm model, string fields, string tableName) where Tm : BaseModel, new();

        /// <summary>
        ///  新增或修改集合中对象，如对象存在则修改对象，反之则新增对象
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="list">待处理对象集合</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="tableName">待处理对象在数据库中对应表名</param>
        /// <returns>返回受影响的记录数</returns>
        int _AddOrModify<Tm>(List<Tm> list, string fields, string tableName) where Tm : BaseModel, new();

        /// <summary>
        /// 获取符合条件的对象
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="filter">筛选条件</param>
        /// <param name="sorts">排序字段及其方式</param>
        /// <param name="tableName">待处理对象在数据库中对应表名</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回符合条件的对象</returns>
        Tm _GetModel<Tm>(string fields, string filter, string sorts, string tableName, List<DBParameter> parameters) where Tm : BaseModel, new();

        /// <summary>
        /// 获取符合条件的对象
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="id">对象ID</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="tableName">待处理对象在数据库中对应表名</param>
        /// <returns>返回符合条件的对象</returns>
        Tm _GetModel<Tm>(string id, string fields, string tableName) where Tm : BaseModel, new();

        /// <summary>
        /// 获取符合条件的对象
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="parameters">参数集合</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="tableName">待处理对象在数据库中对应表名</param>
        /// <returns>返回符合条件的对象</returns>
        Tm _GetModel<Tm>(List<DBParameter> parameters, string fields, string tableName) where Tm : BaseModel, new();

        /// <summary>
        /// 获取符合条件的对象
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="filter">筛选条件</param>
        /// <param name="sorts">排序字段及其方式</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回符合条件的对象</returns>
        Tm _GetModel<Tm>(string fields, string filter, string sorts, List<DBParameter> parameters) where Tm : BaseModel, new();

        /// <summary>
        /// 获取符合条件的对象
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="id">对象主键值</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <returns>返回符合条件的对象</returns>
        Tm _GetModel<Tm>(string id, string fields) where Tm : BaseModel, new();

        /// <summary>
        /// 获取符合条件的对象
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="id">对象主键值</param>     
        /// <returns>返回符合条件的对象</returns>
        Tm _GetModel<Tm>(string id) where Tm : BaseModel, new();

        /// <summary>
        /// 获取符合条件的对象
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="parameters">参数集合</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <returns>返回符合条件的对象</returns>
        Tm _GetModel<Tm>(List<DBParameter> parameters, string fields) where Tm : BaseModel, new();

        /// <summary>
        /// 获取符合条件的对象
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="sql">SQL语句</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回符合条件的对象</returns>
        Tm _GetModel<Tm>(string sql, List<DBParameter> parameters) where Tm : BaseModel, new();

        /// <summary>
        /// 获取全部对象集合
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <returns>返回结果</returns>
        List<Tm> _GetList<Tm>() where Tm : BaseModel, new();

        /// <summary>
        /// 执行SQL语句，返回符合条件的对象集合
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="sql">SQL语句</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回结果</returns>
        List<Tm> _GetList<Tm>(string sql, List<DBParameter> parameters) where Tm : BaseModel, new();

        /// <summary>
        /// 获取符合条件的对象集合
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="filter">筛选条件</param>
        /// <param name="sorts">排序字段及其方式</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回结果</returns>
        List<Tm> _GetList<Tm>(string fields, string filter, string sorts, List<DBParameter> parameters) where Tm : BaseModel, new();

        /// <summary>
        /// 以分页形式获取符合条件的结果
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="pageIndex">获取页的索引</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="recordCount">总记录数。为-1时，将从数据库获取该值</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="filter">筛选条件</param>
        /// <param name="sorts">排序字段及其方式</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回结果</returns>
        List<Tm> _GetList<Tm>(int? pageIndex, int? pageSize, ref int? recordCount, string fields, string filter, string sorts, List<DBParameter> parameters) where Tm : BaseModel, new();

        /// <summary>
        /// 获取全部对象
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="tableName">待处理对象在数据库中对应表名</param>
        /// <returns>返回结果</returns>
        List<Tm> _GetList<Tm>(string tableName) where Tm : BaseModel, new();

        /// <summary>
        /// 获取符合条件的集合
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="filter">筛选条件</param>
        /// <param name="sorts">排序字段及其方式</param>
        /// <param name="tableName">待处理对象在数据库中对应表名</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回结果</returns>
        List<Tm> _GetList<Tm>(string fields, string filter, string sorts, string tableName, List<DBParameter> parameters) where Tm : BaseModel, new();

        /// <summary>
        /// 以分页形式获取符合条件的结果
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="pageIndex">获取页的索引</param>
        /// <param name="pageSize">分页大小</param>
        /// <param name="recordCount">总记录数。为-1时，将从数据库获取该值</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="filter">筛选条件</param>
        /// <param name="sorts">排序字段及其方式</param>
        /// <param name="tableName">待处理对象在数据库中对应表名</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回结果</returns>
        List<Tm> _GetList<Tm>(int? pageIndex, int? pageSize, ref int? recordCount, string fields, string filter, string sorts, string tableName, List<DBParameter> parameters) where Tm : BaseModel, new();

        /// <summary>
        /// 通过IDataReader获取对象
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="dr">IDataReader</param>
        /// <returns>返回对象</returns>
        Tm _GetModel<Tm>(IDataReader dr) where Tm : BaseModel, new();

        /// <summary>
        /// 通过DataRow获取对象
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="dr">DataRow</param>
        /// <returns>返回对象</returns>
        Tm _GetModel<Tm>(DataRow dr) where Tm : BaseModel, new();

        /// <summary>
        /// 通过DataRowView获取对象
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="dv">DataView</param>
        /// <returns>返回对象</returns>
        Tm _GetModel<Tm>(DataRowView dv) where Tm : BaseModel, new();

        /// <summary>
        /// 通过IDataReader返回对象集合
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="dr">IDataReader</param>
        /// <returns>返回对象集合</returns>
        List<Tm> _GetList<Tm>(IDataReader dr) where Tm : BaseModel, new();

        /// <summary>
        /// 通过DataTable获取对象集合
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="dt">DataTable</param>
        /// <returns>返回对象集合</returns>
        List<Tm> _GetList<Tm>(DataTable dt) where Tm : BaseModel, new();

        /// <summary>
        /// 通过DataView返回对象集合
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="dv">DataView</param>
        /// <returns>返回对象集合</returns>
        List<Tm> _GetList<Tm>(DataView dv) where Tm : BaseModel, new();

        /// <summary>
        /// 获取符合条件的对象
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="sqlInfo">封装的筛选信息</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回对象</returns>
        Tm _GetModel<Tm>(SqlInfo sqlInfo, List<DBParameter> parameters) where Tm : BaseModel, new();

        /// <summary>
        /// 获取符合条件的对象集合
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="sqlInfo">封装的筛选信息</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回对象集合</returns>
        List<Tm> _GetList<Tm>(SqlInfo sqlInfo, List<DBParameter> parameters) where Tm : BaseModel, new();

        /// <summary>
        /// 以分页形式返回符合条件的对象集合
        /// </summary>
        /// <typeparam name="Tm">对象泛型类型</typeparam>
        /// <param name="pageInfo">封装的分页数据筛选信息</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回结果</returns>
        List<Tm> _GetList<Tm>(PageInfo pageInfo, List<DBParameter> parameters) where Tm : BaseModel, new();



        List<Tm> _GetTop<Tm>(int count) where Tm : BaseModel, new();
        List<Tm> _GetTop<Tm>(int count, string sorts) where Tm : BaseModel, new();
        List<Tm> _GetTop<Tm>(int count, string fields, string filter, string sorts, List<DBParameter> parameters) where Tm : BaseModel, new();

        List<Tm> _GetTop<Tm>(string tableName, int count) where Tm : BaseModel, new();
        List<Tm> _GetTop<Tm>(string tableName, int count, string sorts) where Tm : BaseModel, new();
        List<Tm> _GetTop<Tm>(string tableName, int count, string fields, string filter, string sorts, List<DBParameter> parameters) where Tm : BaseModel, new();

        int _InsertOrUpdateBySQL<Tm>(Tm model) where Tm : BaseModel, new();
        int _InsertOrUpdateBySQL<Tm>(List<Tm> list) where Tm : BaseModel, new();
        int _InsertOrUpdateBySQL<Tm>(Tm model, string fields) where Tm : BaseModel, new();
        int _InsertOrUpdateBySQL<Tm>(List<Tm> list, string fields) where Tm : BaseModel, new();
        int _InsertOrUpdateBySQL<Tm>(Tm model, string fields, string tableName) where Tm : BaseModel, new();
        int _InsertOrUpdateBySQL<Tm>(List<Tm> list, string fields, string tableName) where Tm : BaseModel, new();
    }
}
